//
//  NavViewController.m
//  Eath
//
//  Created by yuhaya on 14-8-23.
//  Copyright (c) 2014年 yuhaya. All rights reserved.
//

#import "NavViewController.h"
#import "LoginViewController.h"
#import "CenterViewController.h"


@interface NavViewController ()

@end

@implementation NavViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

-(void) changeViewController:(Class)aClass byKey:(NSString *)key
{
    UIViewController * ViewController = [[aClass alloc] init];
    
    if([ViewController isKindOfClass:[LoginViewController class]]){
        
        LoginViewController * login = (LoginViewController *)ViewController;
        login.delegate = self;
        if([self.viewControllers indexOfObject:login] != NSNotFound){
            [self popToViewController:login animated:YES];
        }else if(login != self.topViewController){
            [self pushViewController:login animated:YES];
        }
    }else{
        if([self.viewControllers indexOfObject:ViewController] != NSNotFound){
            [self popToViewController:ViewController animated:YES];
        }else if(ViewController != self.topViewController){
            [self pushViewController:ViewController animated:YES];
        }
    }

}

- (void)loginOver
{
        BOOL flag = NO;
        NSArray * controllers = self.viewControllers;
        CenterViewController * center;
        for (int a = 0; a < [controllers count]; a++) {
            if([controllers[a] isKindOfClass:[CenterViewController class]]){
                flag = YES;
                center = controllers[a];
                break;
            }
        }
        if (flag) {
            [self popToViewController:center animated:YES];
        }else{
            [self pushViewController:[[CenterViewController alloc] init] animated:YES];
        }
        
}

- (void)loginFail
{

}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationBar.backgroundColor = [UIColor blackColor];
    self.navigationBar.opaque = YES;
    
    self.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:NSForegroundColorAttributeName];
    // Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)dealloc
{
    self.delegate = nil;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
